﻿<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>    


<head>
	<script type="text/javascript">
		$(function(){
				init();
			
		});
		function init(){
			$('#t-tree').tree({
				onClick:function(node){
					$('#t-dg').datagrid('reload', {t:node.id});
				}
			});
		}

		function formatvisable(value,row){
   if (row.visable == 0){
      return "不显示";
   } else {
      return "显示";
   }
}

		
		function formatlarge(value,row){
			   if (row.large == 0){
			      return "小图标";
			   } 
			   if (row.large == 1){
				      return "大图标";
			   }
			}

		

		var actionUrl;
		function newItem(){
			$('#dlg').dialog('setTitle', '新增功能菜单').dialog('open');
			$('#myform').form('clear');
			actionUrl = '<c:url value="/system/Menu/saveMenu"/>';
		}
		function editItem(){
			var t = $('#t-dg');
			var row = t.datagrid('getSelected');
			if (row){
				$('#myform').form('load', row);
				$('#dlg').dialog('setTitle', '修改功能菜单').dialog('open');
				actionUrl = '<c:url value="/system/Menu/updateMenu"/>?id=' + row.id;
			}
		}
		
		function deleteItem(){
			var t = $('#t-dg');
			var row = t.datagrid('getSelected');
			if (row){
				
				$.messager.confirm('删除确认', '是否确定要删除选择功能菜单?', function(r){
						if (r){
				$.ajax({
					url:'<c:url value="/system/Menu/destroyMenu"/>?id=' + row.id,
					type:'post',
					success:function(){
						$('#t-tree').tree('reload'); 
						$('#t-dg').datagrid('reload');
						$('#parentid').combotree('reload'); 
					}
				});
			}});
				
			}
		}
		
		function saveItem(){
			$('#myform').form('submit', {
				url:actionUrl,
				onSubmit:function(){
					return $('#myform').form('validate');
				},
				success:function(data){
					var data = eval('('+data+')');
					if (data.success){
						$('#dlg').dialog('close');
						$('#t-dg').datagrid('reload');
						$('#t-tree').tree('reload');
						$('#parentid').combotree('reload'); 
					} else {
						$.messager.show({
							title:'保存失败',
							msg:'<pre>'+data.msg+'</pre>'
						});
					}
				}
			});
		}

		function move(dir){
			var row = $('#t-dg').datagrid('getSelected');
			$.getJSON('<c:url value="/system/menu/move"/>', {id:row.id,dir:dir}, function(){
				$('#t-dg').datagrid('reload');
				$('#t-tree').tree('reload');
				$('#parentid').combotree('reload'); 
			});
		}
	</script>
</head>
<body>
	<div class="easyui-layout" fit="true">
		<div region="north" border="false" style="height:40px;padding:5px;overflow:hidden;" >			
			<a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="newItem()">新增菜单</a>
			<a href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="editItem()">修改菜单</a>
			<a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="deleteItem()">删除菜单</a>
			<a href="#" class="easyui-linkbutton" plain="true" onclick="move('up')">上移</a>
			<a href="#" class="easyui-linkbutton" plain="true" onclick="move('down')">下移</a>			
		</div>
		
		<div region="west" border="true" style="border-right:1px solid #e3e9ff;width:150px;">
			<div style="background:#fafafa;padding-left:5px;">
				
			</div>
			<div style="padding:5px;">
				<ul id="t-tree" url="<c:url value='/system/Menu/getTreeItems'/>"></ul>
			</div>
		</div>

		<div region="center" border="true">
			<table id="t-dg" class="easyui-datagrid"
					url="<c:url value='/system/Menu/getMenuItems'/>"
					singleSelect="true" rownumbers="true" pagination="true"
					border="false" fit="true" fitColumns="true">
				<thead>
					<tr>
<th field="menuid" width="100" sortable="true">菜单ID</th>					
<th field="name" width="100" sortable="true">名称</th>
<th field="url" width="100" sortable="false">访问路径</th>
<th field="icon" width="50" sortable="false">图标</th>
<th field="large" width="50" sortable="false" formatter="formatlarge">图标类型</th>
<th field="visable" width="100" sortable="true" formatter="formatvisable">显示</th>
<th field="groupid" width="100" sortable="true">分组号</th>
<th field="caption" width="150">简要说明</th>

					</tr>
				</thead>
			</table>
		</div>
	</div>
	
<div id="dlg" style="width:400px;
<c:if test="${cfgs['menulayout'] == 'default'}">
height:380px; 
</c:if>
<c:if test="${cfgs['menulayout'] == 'topbottom'}">
height:250px; 
</c:if>
;"
			class="easyui-dialog" closed="true" modal="true" buttons="#dlg-buttons">
		<div style="padding:10px">
			<div style="float:left">
				<form id="myform" method="post" style="margin:0;padding:0">
					<table>
						<tr>
<td style="width:80px">菜单ID</td>
<td><input type="text" class="easyui-validatebox e-input" id="menuid" name="menuid" style="width:250px;" required="true" editable="true"></input></td>
</tr>	

						<tr>
<td style="width:80px">名称</td>
<td><input type="text" class="easyui-validatebox e-input" id="name" name="name" style="width:250px;" required="true" editable="true"></input></td>
</tr>	
<tr>
<td style="width:80px">访问路径</td>
<td><input type="text" class="easyui-validatebox e-input" id="url" name="url" style="width:250px;" required="true" editable="true"></input></td>
</tr>	
<tr>
<td style="width:80px">图标</td>
<td><input type="text" class="easyui-validatebox e-input" id="url" name="icon" style="width:250px;" editable="true"></input></td>
</tr>	
<tr>
<td style="width:80px">图标类型</td>
<td>
<select id="large" name="large" required="true" editable="true" panelHeight="auto" class="easyui-combobox" style="width:250px;">
		<option value="0">小图标</option>		
		<option value="1">大图标</option>
</select></td>
</tr>
<tr>
<td style="width:80px">显示</td>
<td>
<select id="visable" name="visable" required="true" editable="true" panelHeight="auto" class="easyui-combobox" style="width:250px;">
		<option value="0">无权限不显示</option>		
		<option value="1">无权限显示</option>
</select></td>
</tr>	


<tr>
<td style="width:80px">上级菜单</td>
<td><input type="text" class="easyui-combotree"
											style="width:250px;"
											id="parentid" 
											name="parentid" 
											required="true" editable="false"
											url="<c:url value='/system/Menu/getTreeItems'/>"></td>
</tr>	
<tr>
<td style="width:80px">分组号</td>
<td><input type="text" class="easyui-numberspinner" increment="1" min="0" max="100" id="groupid" name="groupid" style="width:250px;" required="true" editable="true" value="0"></input></td>
</tr>
<tr>
<td style="width:80px">简要说明</td>
<td>
<textarea style="width:250px;height:100px;border:1px solid #ccc;font-size:12px;"
										name="caption"></textarea>
</td>
</tr>
				
				
				
								
					</table>
				</form>
			</div>			
			<div style="clear:both"></div>
		</div>
		<div id="dlg-buttons" style="text-align:center;">
			<a href="#" class="easyui-linkbutton" iconCls="icon-save" onclick="saveItem()">保存</a>
			<a href="#" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')">取消</a>
		</div>
</div>

	

</body>
